package logic

import (
	"context"
	"goods_srv/models/mysql"
	"time"

	"goods_srv/goodssrv"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *goodssrv.UserListRequest) (*goodssrv.UserListResponse, error) {
	// todo: add your logic here and delete this line
	var users []mysql.User
	mysql.DB.Debug().Find(&users)
	var userList []*goodssrv.UserList
	for _, v := range users {
		userList = append(userList, &goodssrv.UserList{
			UserId:    int64(v.ID),
			Username:  v.Username,
			Phone:     v.Phone,
			CreatedAt: v.CreatedAt.Format(time.DateTime),
			Status:    int64(v.Status),
		})
	}
	return &goodssrv.UserListResponse{
		List: userList,
	}, nil
}
